package com.lw.user.service;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lw.base.client.result.BaseResult;
import com.lw.user.dal.dao.BizUserDao;
import com.lw.user.dal.entity.BizUser;
import com.lw.userclient.model.BizUserModel;
import com.lw.userclient.param.BizUserParam;
import com.lw.userclient.service.IBizUserService;

@Service("iBizUserService")
public class IBizUserServiceImpl implements IBizUserService{

	@Autowired
	private BizUserDao dao;
	
	public BaseResult<Boolean> createBizUser(BizUserParam param) {
		try {
			BizUser bizUser = new BizUser();
			BeanUtils.copyProperties(param, bizUser);
			int i = dao.createUser(bizUser);
			if(i < 1){
				return new BaseResult<Boolean>(false);
			}else {
				return new BaseResult<Boolean>(true);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return new BaseResult<Boolean>(null,BaseResult.FAIL,false,e.getMessage());
		}
	}

	public BaseResult<BizUserModel> getBizUserByLoginId(String loginId) {
		try {
			BizUser bizUser = dao.selectByLoginId(loginId);
			if(bizUser != null){
				BizUserModel bizUserModel = new BizUserModel();
				BeanUtils.copyProperties(bizUser, bizUserModel);
				return new BaseResult<BizUserModel>(bizUserModel);
			}else {
				return new BaseResult<BizUserModel>(null);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			return new BaseResult<BizUserModel>(null,BaseResult.FAIL,false,e.getMessage());
		}
	}

	public BaseResult<Boolean> checkBizUserExist(String loginId) {
		try {
			BizUser bizUser = dao.selectByLoginId(loginId);
			if(bizUser != null){
				return new BaseResult<Boolean>(true);
			}else {
				return new BaseResult<Boolean>(false);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return new BaseResult<Boolean>(null,BaseResult.FAIL,false,e.getMessage());
		}
	}
}
